package low;

import java.util.Arrays;

/**
 * 557. 反转字符串中的单词 III
 */
public class ReverseWords {
    public static void main(String[] args) {
        String str = "hello world";
        String arrays = reverseWords(str);
        System.out.println(arrays);
    }

    public static String reverseWords(String s) {
        String[] strings = s.split(" ");
        StringBuilder stringBuilder = new StringBuilder();
        for (String str:strings){
            char[] chars = str.toCharArray();
            int left = 0;
            int right=chars.length-1;
            while (left<right){
                char tmp = chars[left];
                chars[left] = chars[right];
                chars[right] = tmp;
                left++;
                right--;
            }
            stringBuilder.append(String.valueOf(chars)).append(" ");
        }
        String result = stringBuilder.substring(0,stringBuilder.length()-1);
        return result;
    }


}
